package com.roubsite.sso.utils;

public class RSOauthClient {
	private String oauthUri = "";
	private String appId = "";
	private String appSecret = "";
	private static SignData sd = new SignData();

	/**
	 * 
	 * @param oauthUrl oauth服务器提供的地址
	 */
	public RSOauthClient(String oauthUrl, String app_id, String app_secret) {
		oauthUri = oauthUrl;
		appId = app_id;
		appSecret = app_secret;
	}

	/**
	 * 自动拼装获取code和access_token的url
	 * 
	 * @return
	 * @throws Exception
	 */
	public String getCodeaccessTokenRequestUrl(String redirectUri) throws Exception {
		String sign = sd.signWhole(appId + redirectUri);
		return oauthUri + "/getAuthorizationCode?system_id=" + appId + "&redirect_uri=" + redirectUri + "&sign" + sign;
	}

	public String getUserInfoUrl(String code, String access_token) throws Exception {
		String sign = sd.signWhole(access_token + code + appId);
		return oauthUri + "/getUserInfo?access_token=" + access_token + "&code=" + code + "&system_id=" + appId
				+ "&sign" + sign;
	}

}
